package com.wsoft.mq.config;

import com.wsoft.mq.constant.SmsConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author z001
 * @Date 2025/1/14 14:08
 */
@Configuration
public class SmsConfig {

    //################################### to_user ###################################
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange toUserExchange() {
        // 持久化，不自动删除
        return new DirectExchange(SmsConstant.SMS_TO_USER_DIRECT_EXCHANGE, true, false);
    }

    @Bean
    public Queue toUserQueue() {
        //持久化
        return new Queue(SmsConstant.SMS_TO_USER_QUEUE, true);
    }

    @Bean
    public Binding toUserBinding() {
        return BindingBuilder.bind(toUserQueue())
                .to(toUserExchange())
                .with(SmsConstant.SMS_TO_USER_KEY);
    }


}
